//////////////////////////////////////////////////////////////
//
//  Description	: PDF2HTML/BMP software
//  Author	: verypdf.com Inc
//  Version	: Ver1.2
//  Platform	: Windows95/98/Me/NT/2000/XP
//  Environment	: Visual C++ 6.0
//  Date	: 2002/04/03
//
//  Copyright(C) 2000--2003 verypdf.com Inc
//      
//  Contact infomation:
//        http://www.verypdf.com/
//        support@verypdf.com
//
//  This program is shareware; you can redistribute and/or 
//  modify it under the terms of the GNU General Public License.
//  See the GNU General Public License for more details.
//
//               Portion base on Xpdf code
//         Copyright 1996-2003 Glyph && Cog, LLC
//////////////////////////////////////////////////////////////

#ifndef __PDFCORE_H__
#define __PDFCORE_H__

#include <string>
#include <vector>
using namespace std;

typedef HANDLE	HPDF;
typedef HANDLE  HCHARSET;
#define DllExport   __declspec( dllexport )

//Description one character infomation
typedef struct STEXTtag
{
        INT                     x,y;            //Character coordinate(left and top position)
        string                  szCode;         //Character content(Unicode enconding)
        INT                     nCount;         //Character number,in bytes
        string                  szFontName;     //Font name
        INT                     nFontWidth;     //Font width,unit pixel
        INT                     nFontHeight;    //Font height,unit pixel
        BOOL                    m_bIsBold;      //The font is bold
        BOOL                    m_bIsItalic;    //The font is italic
        INT                     m_dAngle;       //Roate font with specify angle
        COLORREF                color;          //Font color
        BYTE                    style;          //Font style, reserved
}STEXT,*LPSTEXT;

//Description image infomation
typedef struct _tagBITMAPINFO 
{
        BITMAPINFOHEADER    bmiHeader;          //Bitmap infomation header
        RGBQUAD             bmiColors[256];     //Bitmap color palette,for truecolor image,don't use bmiColors member
} BITMAPINFO2,*LPBITMAPINFO2;
typedef struct SIMAGEtag
{
        BITMAPINFO2             nBitmapInfo;    //Bitmap infomation and color palette
        INT                     x,y;            //Image x and y coordinate,left and top position
        INT                     cx,cy;          //Image width and height,unit is pixel
        vector<BYTE>            pData;          //Image data,store in bitmap format

	BOOL			m_bIsText;      //This image is text? for embed font text
	STEXT			m_nImageText;   //embed font text
}SIMAGE,*LPSIMAGE;

//Description line infomation
typedef struct SLINEtag
{
        INT             x0,y0,x1,y1;            //Line begin coordinate and end coordinate
        INT             width;                  //Line width
        COLORREF        color;                  //Line color
        INT             style;                  //Line style,it can be any one of following values: 
                                                //PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME
}SLINE,*LPSLINE;

//Description polygon infomation
typedef struct SPOLYGONtag
{
        vector<POINT>   pots;                   //Pointer to an array of POINT structures that define the vertices 
                                                //of the polygon. The polygon is presumed closed. Each vertex can 
                                                //be specified only once. 
        INT             shape;                  //Reserved
        INT             mode;                   //Specifies the new fill mode. This parameter can be either of the 
                                                //following values: ALTERNATE,WINDING. 
        INT             brushmode;              //Brush mode,reserved
        COLORREF        color;                  //Fill color within polygon
        INT             width;                  //Stroke line width
}SPOLYGON,*LPSPOLYGON;

//Description clipping region infomation
typedef struct SCLIPPINGRGNtag
{
        vector<BYTE>    m_aryClipRegion;        //Clipping region data,you can use ::ExtCreateRegion() to create clipping region
}SCLIPPINGRGN,*LPSCLIPPINGRGN;

//PDF page elements
typedef enum EPAGECONTENTtype
{
	PDF_NULL,
        PDF_TEXT,                               //Text type
        PDF_IMAGE,                              //Image type
        PDF_LINE,                               //Line type
        PDF_POLYGON,                            //Polygon type
        PDF_CLIPPINGRGN                         //Clipping region
}EPAGECONTENT;

//Page infomation
typedef	struct SCONTENTtag
{
        EPAGECONTENT            m_type;         //Page element type
//----------------------------------------------
        LPSTEXT                 m_Codes;        //Text content
        LPSIMAGE                m_Images;       //Image content
        LPSLINE                 m_Lines;        //Line content
        LPSPOLYGON              m_Polygons;     //Polygon content
        LPSCLIPPINGRGN          m_ClippingRgn;  //Clipping content
//----------------------------------------------
}SCONTENT,*LPSCONTENT;
typedef struct SPAGEtag
{
        INT                     m_Width,m_Height;       //PDF page width and height,in pixel
        INT                     m_No,m_Num;             //Current page no and max pages,between 1 and n-1 (n = max page num)
        INT                     m_DPI;                  //Interpreter resolution
        FLOAT                   m_PDFVersion;           //PDF interpreter version
        vector<LPSCONTENT>      m_pageBlock;            //Page content
}SPAGE,*LPSPAGE;

//Hyperlink in pdf document
typedef struct SHTMLLINKtag
{
        INT     xMin;
        INT     xMax;
        INT     yMin;
        INT     yMax;           //Hyperlink rectangle region position
        string	szDest;         //Hyperlink link to destination
}SHTMLLINK,*LPSHTMLLINK;
typedef vector<SHTMLLINK> ARY_HTMLINK,*LPARY_HTMLINK;

#ifdef __cplusplus
extern "C"{
#endif
//////////////////////////////////////////////////////////////////////////////////////////
//  PDF interpreter library interface function
//////////////////////////////////////////////////////////////////////////////////////////
//Open,close a pdf file,support own and user password
DllExport HPDF                  WINAPI PDF_Open(LPCTSTR pszFileName,LPCTSTR pszOwnPass,LPCTSTR pszUserPass,INT dpi);
DllExport VOID                  WINAPI PDF_Close(HPDF m_hPDF);
//Get page count number in pdf file
DllExport INT                   WINAPI PDF_GetPageCount(HPDF m_hPDF);
//Get special page infomation in PDF file
DllExport LPSPAGE               WINAPI PDF_GetPageObject(HPDF m_hPDF,INT no);
//Destroy page infomation,in order to free memory in page structure
DllExport VOID                  WINAPI PDF_DestroyPageObject(LPSPAGE);
//Render pdf page infomation into DIB format
DllExport HANDLE                WINAPI PDF_GetPageBmp(HPDF m_hPDF,INT no);
//Free DIB memory,avoid memory leak
DllExport VOID                  WINAPI PDF_DestroyPageBmp(HANDLE);
//Get hyperlinks in pdf page
DllExport LPARY_HTMLINK         WINAPI PDF_GetPageHtmLink(HPDF m_hPDF,INT no);
DllExport VOID                  WINAPI PDF_DestroyHtmLink(LPARY_HTMLINK);

/////////////////////////////////////////////////////////////////////////////////////////////
// Description: Extract bookmark from pdf file
// Parameter  : m_hPDF  --  pdf file handle, return by PDF_Open()
//              szFileName -- the buffer of bookmark filename, will be filled in PDF_GetBookmark() function
//              size    -- the size of szFileName, in bytes
// return value: TRUE  --  successed, FALSE  --  this pdf file hasn't bookmark
DllExport BOOL                  WINAPI PDF_GetBookmark(HPDF m_hPDF,LPSTR szFileName,INT size);
//////////////////////////////////////////////////////////////////////////////////////////
//  PDF util functions
//////////////////////////////////////////////////////////////////////////////////////////
//Write pdf page structure into HTML file
DllExport INT           WINAPI PDF_ConvertToHtmlFile(LPSPAGE,LPARY_HTMLINK m_pHtmLink,LPCTSTR pszHtmlFile);
//Write DIB infomation into BMP file
DllExport BOOL          WINAPI PDF_WriteToBMPFile(HANDLE m_hDIBInfo,LPCTSTR pszBmpFile);
//Write pdf page structure info SVG file, keep all vector elements
DllExport BOOL          WINAPI PDF_WriteToSVGFile(LPSPAGE lpPageObj,LPCTSTR pszFileName);

#ifdef __cplusplus
}
#endif

#endif //__PDFCORE_H__